<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<link rel="stylesheet" th:href="@{/assets/css/colorbox.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/My97DatePicker/skin/WdatePicker.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/showLoading/css/showLoading.css}"/>
<head th:include="fragments/head::header"/>
<body>
<div th:include="fragments/top::top"></div>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <div th:include="fragments/left::left" class="sidebar" id="sidebar"></div>
        <div class="main-content">
            <div class="page-content">
                <div th:include="fragments/student_info::student_info"
                     th:style="${session.studentInfoKey == null}? 'display:none'"></div>
                <h3 class="header smaller lighter blue">添加学生信息</h3>
                <div id="ulId" class=""></div>
                <br/>
                <form method="post" id="edit">
                    <div class="tab-pane fade in active">
                        <shiro:hasRole name="同业顾问">
                            <input type="hidden" id="input_counselor" value="1"/>
                        </shiro:hasRole>
                        <shiro:hasRole name="机构">
                            <input type="hidden" id="input_agent" value="1"/>
                        </shiro:hasRole>
                        <shiro:hasRole name="同业经理">
                            <input type="hidden" id="input_manager" value="1"/>
                        </shiro:hasRole>

                        <input type="hidden" id="input_nationName" name="nationName"/>
                        <input type="hidden" id="input_auditStatus" name="auditStatus"/>
                        <input type="hidden" name = "agentId" th:value="${agentId != null}?${agentId}"/>
                        <div class="container">
                            <div class="form-horizontal">
                                <div class="form-group" style="height:29px;">
                                    <label class="col-sm-3 control-label no-padding-right no-padding-left blue">姓<span style="color: white;">站位</span>名：</label>
                                    <span class="col-sm-2"><input  name="studentName"/><span style="color: red;margin-left: 5px;">* </span></span>
                                    <label class="col-sm-3 control-label no-padding-right blue">拼<span style="color: white;">站位</span>音：</label>
                                    <span><input name="pinyin" class="col-sm-2"/><span style="color: red;margin-left: 5px;">* </span></span>
                                </div>

                                <div class="form-group" style="height:29px">
                                    <label class="col-sm-3 control-label no-padding-right blue">出生日期：</label>
                                    <span class="col-sm-3"><input class="Wdate" placeholder="yyyy-MM-dd" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" style="width: 190px" name="birthday" required="required"/><span style="color: red;margin-left: 5px;">* </span></span>
                                    <label class="col-sm-2 control-label no-padding-right blue">性<span style="color: white;">站位</span>别：</label>
                                    <div class="col-sm-3 input-sm">
                                        <input type="radio" name="gender" value="1" checked="checked"/>男
                                        <input type="radio" name="gender" value="0"/>女
                                        <span style="color: red;margin-left: 5px;">* </span>
                                    </div>
                                </div>

                                <div class="form-group" style="height:29px">
                                    <label class="col-sm-3 control-label no-padding-right blue">留学国家：</label>
                                    <select type="" class="col-sm-3 form-control input-sm" id="select_nation" name="nationId" style="width:190px;height:25px;">
                                        <option th:each="item: ${list_country}" th:value="${item.id}" th:text="${item.countryName}"></option>
                                    </select>
                                    <span class="col-sm-1 no-padding-right red" >* </span>
                                    <span>
                                        <label class="col-sm-3 control-label no-padding-right blue">类<span style="color: white;">站位</span>型：</label>
                                        <select type="" class="col-sm-3 form-control input-sm" name="contractType" style="width:190px;height:25px;">
                                            <option value="-1">请选择</option>
                                            <option value="1">全程</option>
                                            <option value="4">单签证</option>
                                        </select>
                                        <span style="color: red;margin-left: 5px;">* </span>
                                    </span>
                                </div>

                                <div class="form-group" style="height:29px">
                                    <label class="col-sm-3 control-label no-padding-right no-padding-left blue">签约日期：</label>
                                    <input class="col-sm-2" disabled="disabled"/>
                                    <label class="col-sm-3 control-label no-padding-right blue">代理QQ：</label>
                                    <input class="col-sm-2" name="agentQq"/>
                                </div>

                                <div class="form-group" style="height:29px;">
                                    <label class="col-sm-3 control-label no-padding-right no-padding-left blue">代理类型：</label>
                                    <input class="col-sm-2" readonly="readonly" value="与代理直接签约"/>
                                    <label class="col-sm-3 control-label no-padding-right no-padding-left blue">代理名称：</label>
                                    <input class="col-sm-2" readonly="readonly" name="agentName" th:value="${agentName != null}?${agentName}"/>
                                </div>

                                <div class="form-group" style="height:29px;">
                                    <label class="col-sm-3 control-label no-padding-right blue">学<span style="color: white;">站位</span>号：</label>
                                    <input class="col-sm-2" id="input_studentNo" name="studentNo" th:value="${studentNo}" readonly="readonly"/>
                                    <label class="col-sm-3 control-label no-padding-right blue">分支机构：</label>
                                    <input class="col-sm-2" readonly="readonly" value="澳际同业"/>
                                </div>

                                <div class="form-group" style="height:29px;">
                                    <label class="col-sm-3 control-label no-padding-right blue">对接邮箱：</label>
                                    <span><textarea placeholder="(多个用;分开)" class="col-sm-7" name="email"></textarea><span style="color: red;margin-left: 5px;">* </span></span>
                                </div>
                                <div class="form-group" style="height:29px;margin-top: 30px;">
                                    <label class="col-sm-3 control-label no-padding-right no-padding-left blue">转案备注：</label>
                                    <textarea  class="col-sm-7" name="transferRemark" rows="10"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

                <div class="modal-footer" style="margin-bottom: 5px;">
                    <shiro:hasAnyRoles name="同业经理,机构, 同业顾问">
                        <button type="button" class="btn btn-primary" id="save">保存</button>
                        <shiro:hasRole name="机构">
                            <button type="button" class="btn btn-primary" id="submits">提交</button>
                        </shiro:hasRole>
                    </shiro:hasAnyRoles>
                </div>

                <span>
                    <select type="" class="col-sm-3 form-control input-sm" id="select_papersType" style="width:190px;height:25px;" >
                        <option value="1">申请材料</option>
                        <option value="2">签证材料</option>
                    </select>
                    <h3 class="header small lighter blue" style="margin-top: 2%;"></h3>
                </span>

                <div flag="template" style="display: none;">
                    <div>
                        <input type="hidden" flag="papersTypeId"/>
                        <span style="margin-left: 10%;" flag="papersTypeName"></span>
                        <button type="button" class="btn-primary1 pull-right" style="margin-right: 5%;width: 60px;height: 25px;" flag="btnUpload" >上传</button>
                    </div>
                    <div style="margin-left: 10%;" flag="div_file">

                    </div>
                    <h3 class="header smaller lighter black" style="margin-left: 10%;margin-right: 10%;"></h3>
                </div>

                <form method="post" action="/uploadFiles" id="form_file" enctype="multipart/form-data" style="display: none;">
                    <!--<div class="container">-->
                        <!--<div class="form-horizontal">-->
                            <!--<div class="form-group">-->
                                <div class="col-sm-12" style="padding-left: 0px;" id="div_attachment">
                                    <div class="widget-header">
                                        <h4>文件上传</h4>
                                    </div>
                                    <div class="widget-body">
                                        <div class="widget-main">
                                            <input name="fileInput" multiple="multiple" type="file" id="id-input-file-3"/>
                                            <label>
                                                <input type="checkbox" name="file-format" id="id-file-format" class="ace"/>
                                            </label>
                                            <span style="color: #FF2F2F">*上传文件的格式为&nbsp;:&nbsp;&nbsp; .jpg，&nbsp;.png，&nbsp;.gif,&nbsp;.doc，&nbsp;.docx，&nbsp;.pdf</span>
                                        </div>
                                    </div>
                                </div>
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                </form>

                <div id="alert" class="alert alert-success" style="display: none;" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <span id="alertText"></span>
                </div>
                <br/><br/><br/><br/><br/><br/><br/><br/>
            </div>
        </div>
        <div th:include="fragments/bottom::bottom"></div>
    </div>

    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="icon-double-angle-up icon-only bigger-110"></i>
    </a>
</div>
<!-- Modal备注 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">

        </div>
    </div>
</div>
<!-- Modal备注 -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <h2 style="color: green" id="result">审核通过</h2>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div>
    </div>
</div>
<div th:include="fragments/js::js"></div>
<script th:src="@{/assets/js/jquery.inputlimiter.1.3.1.min.js}"></script>
<script th:src="@{/assets/js/jquery.maskedinput.min.js}"></script>
<script th:src="@{/assets/js/bootstrap-tag.min.js}"></script>
<script th:src="@{/assets/js/ace-elements.min.js}"></script>
<!--<script th:src="@{/assets/js/ace.min.js}"></script>-->
<script th:src="@{/assets/js/jquery.form.js}"></script>
<script th:src="@{/js/upload/upload.js}"></script>
<!-- page specific plugin scripts -->
<script th:src="@{/assets/js/jquery.dataTables.min.js}"></script>
<script th:src="@{/assets/js/jquery.dataTables.bootstrap.js}"></script>
<script th:src="@{/assets/js/temp.js}" charset="UTF-8"></script>
<!--图片查看器-->
<script th:src="@{/assets/js/jquery.colorbox-min.js}"></script>
<script th:src="@{/layer/layer.js}"></script>
<script th:src="@{/My97DatePicker/WdatePicker.js}"></script>
<script th:src="@{/business/common.js}"></script>
<script th:src="@{/showLoading/js/jquery.showLoading.min.js}"></script>
<script type="text/javascript">
    <!--
    jQuery(function ($) {
        var pageHelper = (function () {
            this.addStudent = function (uploadComplete) {
                if ($("input[name='studentName']").val() == "") {
                    layer.alert('请填写姓名！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }
                if ($("input[name='pinyin']").val() == "") {
                    layer.alert('请填写拼音！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }

                var reg_pinyin = new RegExp("^(?!_)([A-Za-z ]+)$");
                if (!reg_pinyin.test($("input[name='pinyin']").val())) {
                    layer.alert('请填写正确格式的拼音！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }

                if ($("input[name='birthday']").val() == "") {
                    layer.alert('请填写出生日期！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }
                if ($("textarea[name='email']").val() == "") {
                    layer.alert('请填写对接邮箱！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }

                var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
                var regMails = new RegExp("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+(\\s)*(;)*((\\s)*(;)+(\\s)*[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+(;)*)*$");
                if (!regMails.test($("textarea[name='email']").val())) {
                    layer.alert('请填写正确格式的电子邮箱！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }

                var reg_num = new RegExp("^[0-9]*$");
                if ($("input[name='agentQq']").val() != "" && !reg_num.test($("input[name='agentQq']").val())) {
                    layer.alert('请填写正确格式的QQ号码！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }

                if ($("select[name='contractType']").children("option:selected").val() == "-1") {
                    layer.alert('请选择类型！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }
                if ($("select[name='nationId']").children("option:selected").val() == "-1") {
                    layer.alert('请选择留学国家！', {icon: 0});
                    $("#save").removeAttr("disabled");
                    $("#submits").removeAttr("disabled");
                    return;
                }
                if (!uploadComplete) {
                    layer.msg('正在上传中,请稍后保存!');
                    return;
                }
                $.ajax({
                    url: "/channelStudent/add",
                    type: "post",
                    data: $("#edit").serialize(),
                    success: function (data) {
                        if (data) {
                            if($("#input_counselor").val() == "1" || $("#input_manager").val() == "1") {
                                location.href = '/toAuditListTY';
                            }
                            else if($("#input_agent").val() == "1") {
                                location.href = '/toAuditListDL';
                            }
                        } else {
                            $("#save").removeAttr("disabled");
                            $("#submits").removeAttr("disabled");
                            $('#alertText').text('操作失败');
                            $('#alert').attr('class', 'alert alert-danger').show();
                            setTimeout("$('#alert').hide()", 2000);
                            $("#myModal").modal("hide");
                        }
                    }
                });
            }
            this.getPapersType = function(studentNo){
                $(".main-container").showLoading();
                $("div[flag='template']:visible").remove();
                var nationId = $("#select_nation").children("option:selected").val();
                var papersType = $("#select_papersType").children("option:selected").val();
                $.post("/channelStudent/getPapersType",{"studentNo":studentNo,"nationId":nationId,"papersType":papersType},function (data,status) {
                    if(data["code"] == 1){
                        for (var i=0;i<data["data"].length;i++){
                            var item = data["data"][i];
                            var html = $("div[flag='template']:hidden").clone();
                            html.children("div").children("input").val(item["paperId"]);
                            html.children("div").children("span").text(item["paperName"]);
                            html.show();
                            $("div[flag='template']:hidden").after(html);
                        }
                    }
                    $(".main-container").hideLoading();
                })
            }
            return {
                init: function () {
                    this.getQueryData();
                    this.handelQueryData();
                    this.render();
                    this.addEvent();
                },
                getQueryData: function () {
                    this.paperType = 1;
                    this.paperId = -1;
                    this.uploadComplete = true;
                    this.layerIndex;
                    this.studentNo = $("#input_studentNo").val();
                    this.nationId;
                },
                handelQueryData: function () {

                },
                render: function () {
                    var _self = this;
                },
                addEvent: function () {
                    var _self = this;
                    $("#save").click(function () {
                        $("#input_auditStatus").val("1");
                        $(this).attr("disabled", "disabled");
                        addStudent(_self.uploadComplete);
                    });
                    $("#submits").click(function () {
                        $("#input_auditStatus").val("2");
                        $(this).attr("disabled", "disabled");
                        addStudent(_self.uploadComplete);
                    });

                    $("#select_nation").change(function () {
                        var nationName = $(this).children("option:selected").text();
                        $("#input_nationName").val(nationName);
                        _self.nationId = $(this).children("option:selected").val();
                        getPapersType(_self.studentNo);
                    });

                    $("#select_papersType").change(function () {
                        _self.paperType = $(this).children("option:selected").val();
                        getPapersType(_self.studentNo);
                    });

                    $(document).on("click",'.btn-primary1',function(){
                        _self.paperId = $(this).parent("div").children("input").val();
                        _self.layerIndex = layer.open({
                            type: 1,
                            title:false,
                            area: ['550px', '219px'],
                            content: $('#form_file')
                        });
                    });
                    $(document).on("click",'.a_del',function(){
                        if(confirm("确定要删除吗?")){
                            var html = $(this);
                            var fileId = $(this).attr("fileId");
                            $.post("/channelStudent/delPaper",{"studentNo":_self.studentNo,"fileId":fileId},function(data,status){
                                if(data == 0){
                                    html.parent().remove();
                                }
                            });
                        }
                    });
                    $("#returnPage").click(function () {
                        location.href = '/channelStudent/studentList';
                    });
                    $('#id-input-file-3').ace_file_input({
                        style: 'well',
                        btn_choose: 'Drop files here or click to choose',
                        btn_change: null,
                        no_icon: 'icon-cloud-upload',
                        droppable: true,
                        thumbnail: 'small',//large | fit
                        // .jpg，&nbsp;.png，&nbsp;.gif,&nbsp;.doc，&nbsp;.docx，&nbsp;.pdf
                        allowExt: ['jpg', 'png', 'gif', 'doc', 'docx', 'pdf'],    //该属性只是对文件后缀的控制
                        before_change: function (files, dropped) {
                            return true;
                        },
                        before_remove: function () {
                            $("#input_attachment").val("");
                            return true;
                        },
                        preview_error: function (filename, error_code) {

                        }
                    }).on('change', function () {
                        //获取文件大小
                        if (!checkUp(this)) {
                            return false;
                        }

                        _self.uploadComplete = false;
                        layer.msg('正在上传中...', {
                            icon: 16,
                            shade: 0.01,
                            time: 5 * 10
                        });
                        $("#form_file").ajaxSubmit(function (message) {
                            _self.uploadComplete = true;
                            if (message) {
                                var code = message.code;
                                var files = message.objNew;
                                var originalFiles = message.originalFiles;
                                if (code == "1") {
                                    layer.alert("请上传正确的文件格式!")
                                } else if (message.success) {
                                    var input = $("input[flag='papersTypeId'][value="+_self.paperId+"]");
                                    var div = input.parent("div").next("div");
                                    for(var i=0;i<files.length;i++){
                                        var fileUrl = files[i];
                                        var originalFilename = originalFiles[i];
                                        $.ajax({
                                            type : "post",
                                            url : "/getPrivateUrl",
                                            data : "fileUrl=" + fileUrl,
                                            async : false,
                                            success : function(data){
                                                layer.close(_self.layerIndex);
                                                $.ajax({
                                                    type : "post",
                                                    url : "/channelStudent/addPaper",
                                                    data : {"studentNo":_self.studentNo,"countryId":_self.nationId,"contractNo": "0","paperType":_self.paperType,"paperId":_self.paperId,"fileName":originalFilename,"fileUrl":fileUrl},
                                                    async : false,
                                                    success : function(fileId){
                                                        if(fileId > 0){
                                                            div.append($("<div><a target='_blank' href='"+data+"'>"+originalFilename+"</a><a class='red a_del' fileId='"+fileId+"'  style='margin-left: 10px;' href='javascript:void(0);'><i class='icon-trash icon-2x icon-only bigger-130'></i></a></div>"));
                                                        }
                                                        else{
                                                            layer.alert("上传失败,请尝试重新上传。");
                                                        }
                                                    }
                                                });
                                            }
                                        });
                                    }
                                }
                            } else {
                                layer.alert("上传失败,请尝试重新上传。");
                            }
                        });
                    });
                    $("#select_nation").trigger("change");
                }
            }
        })();
        pageHelper.init();
    });
    -->

</script>
</body>
</html>
